package com.jiyinit.web.core.common.jsptag;

import com.jiyinit.core.framework.base.util.Check;
import com.jiyinit.web.core.common.constant.Constant;
import com.jiyinit.web.core.common.util.UserUtil;
import com.jiyinit.web.core.common.vo.CurrentUserVo;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.Set;

/**
 * <p></p>
 * <p>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author lishaochuan
 * @version 1.0
 * @date 2017/4/18 17:03
 * @since 1.0
 */
public class AuthTag extends TagSupport {

    private static final long serialVersionUID = 5018589040571048229L;

    /**
     * 权限url
     */
    private String authUrl;

    @Override
    public int doAfterBody() throws JspException {
        return super.doAfterBody();
    }

    @Override
    public int doEndTag() throws JspException {
        return super.doEndTag();
    }

    @Override
    public int doStartTag() throws JspException {
        CurrentUserVo user = UserUtil.getCurrentUser();
        //当前用户url权限
        Set<String> resUrlSet = user.getUrlSet();
        if(Check.isNullCollection(resUrlSet) || !resUrlSet.contains(authUrl)){
            return TagSupport.SKIP_BODY;
        }
        return TagSupport.EVAL_BODY_INCLUDE;
    }

    /**
     * @return the authUrl
     */
    public String getAuthUrl() {
        return authUrl;
    }

    /**
     * @param authUrl the authUrl to set
     */
    public void setAuthUrl(String authUrl) {
        this.authUrl = authUrl;
    }
}
